#!/usr/bin/env bash

k8s_version="1.8.5"
etcd_version="3.0.17"
docker_version="1.12.6"


function download_etcd(){
    etcd_file_name="etcd-v${etcd_version}-linux-amd64.tar.gz"

    if [ ! -f "etcd/${etcd_file_name}" ]; then
        mkdir etcd
        wget -O etcd/${etcd_file_name} --tries 4 https://github.com/coreos/etcd/releases/download/v${etcd_version}/${etcd_file_name} 

        if [ ! $? -eq 0 ]; then
            rm -f etcd/${etcd_file_name}
        fi
    fi
}

function download_docker(){
    docker_file_name="docker-${docker_version}.tgz"

    if [ ! -f "docker/${docker_file_name}" ]; then
        mkdir docker
        wget -O docker/${docker_file_name} --tries 4 https://get.docker.com/builds/Linux/x86_64/${docker_file_name}

        if [ ! $? -eq 0 ]; then
            rm -f docker/${docker_file_name}
        fi
    fi
}

function download_k8s(){
    if [ ! -f "k8s/v${k8s_version}/kubernetes-server-linux-amd64.tar.gz" ]; then
        mkdir -p k8s/v${k8s_version}/
        wget -O k8s/${k8s_version}/kubernetes-server-linux-amd64.tar.gz --tries 4 https://storage.googleapis.com/kubernetes-release/release/v${k8s_version}/kubernetes-server-linux-amd64.tar.gz 
    fi
} 


cd packages

# download_etcd
download_docker
# download_k8s
cd ..